<template>
  <div class="tenantMenu_main main_container">
    <div style="margin:0" class="main_main">
      <div style="padding-right:20px" class="SearchBar_main main_main_search">
        <div style="padding-left:20px" class="main_main_search_item">
          <div class="formItem_header">
            <div class="formItem_header_operate">
              <!-- <a class="formItem_header_operate_items" @click="add">
                <svg-icon icon-class="新增" />
                <div class="item_name">新增</div>
              </a> -->
            </div>
          </div>
        </div>
        <div class="main_main_search_item">
          <el-input v-model="pageData.code" placeholder="请输入领料单号" clearable @keyup.enter.native="getList" @clear="getList" />
          <el-button icon="el-icon-search" @click.stop="getList" />
        </div>
      </div>
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          :row-class-name="tableRowClass"
          :height="tableHeight"

          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @row-click="rowClick"
        >
          <Column v-for="(column,index) in defaultTableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
        </el-table>
      </div>
    </div>
    <!-- <div class="addtype-main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectedNum"
        @pagination="getList"
      />
    </div> -->
  </div>
</template>

<script>
import { listForReturn } from '@/api/ProductionManagement/pickingList'
import AddOrUpdate from './addOrUpdate' // 新增或编辑页面
export default {
  name: 'Index',
  props: {
    layerid: {},
    typeId: {}
  },
  data() {
    return {
      pageData: {
        companyName: undefined,
        orderByColumn: 'updateTime',
        isAsc: 'desc',
        code: ''
      },
      defaultTableColumns: [// 表格常规字段（初始值）
        // { prop: 'code', label: '任务单号' },
        { prop: 'code', label: '领料单号' },
        { prop: 'productTaskCode', label: '任务单号' },
        { prop: 'requisitionName', label: '领料人员' },
        { prop: 'requisitionDate', label: '领料日期' },
        { prop: 'remark', label: '备注' }
      ],
      seachDate: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        searchValue: '',
        status: 1
      },
      typeCodeId: '',
      total: 1, // 数据一共有多少条
      mainId: 'id',
      tableHeight: '0',
      tableData: []
    }
  },
  computed: {
    // 分页器
    selectedNum() {
      return this.$refs.table ? this.$refs.table.selection.length : 0
    }
  },
  watch: {
    'seachDate.searchValue'() {
      if (this.seachDate.searchValue == '' || this.seachDate.searchValue == null) {
        this.getList()
      }
    }
  },
  mounted() {
    this.getList()
    this.$nextTick(() => {
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
    this.typeCodeId = this.typeId
  },
  methods: {
    getList() {
      listForReturn({ ...this.pageData, isReturn: '0' }).then(res => {
        this.tableData = res.data
        this.total = res.total
      })
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    tableRowClass({ row }) {
      if (row.id == this.typeCodeId) {
        return 'rowSelected'
      }
      return ''
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
          }// props
        },
        area: ['880px', '600px'],
        title: '新增生产任务单', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    rowClick(row) { // 单击行选中
      console.log(row, '选择数据')
      this.$parent.chooseOrderCallBack(row)
      this.$layer.close(this.layerid) // 关闭弹框
    }

  }
}
</script>

<style lang="less" scoped>
/deep/ .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: rgba(56, 123, 252, 0.5) !important;
  color: #ffffff;
}
.main_main{
  margin: 0 !important;
  height: calc(100% - 50px);
}
.main_main_search_item{
  .el-input{
    width:230px !important;
    margin-right:10px !important;
  }
  .el-button{
    background:#387bfc !important;
    width:30px !important;
  }
}
.addtype-main_bottom{
  padding-right:20px !important;
}
.formItem_header_operate_items{
  height: 30px;
  display: flex;justify-content: center;align-items: center;
  padding: 0px 10px;font-size: 16px;border-radius: 4px;
  color: rgba(56, 123, 252, 1);background-color: rgba(235, 242, 255, 1);
  margin-left: 10px !important;
  .item_name{
    font-size: 14px;padding-left: 10px;
  }
}
.formItem_header_operate_items:hover{
  background-color: rgba(235, 242, 255, 0.5);
}
</style>
